<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-11-11
 * Time: 上午11:50
 */
use \PFT\Db;
include_once '/var/www/html/new/d/module/common/Db.class.php';
include_once '/var/www/html/new/d/common/func.inc.php';
$dbConf = include_once '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息
$account=array(100001,100019,100089,123492,123545,123624,123628,123757,123999,124124,124304,124375,124472,124503,124530,
        124757,124917,200044,200148,200155,200248,200572,200588,200750,200837,200906,200974,502140,502837,502952,504025,
        504094,504283,504689,505009,505270,511531,516649,516763,516973,517229,517302,517694,200766,100005,517302,124530,
        516371, 123950,100010,511133,200030,100031);



Db::Conf($dbConf['localhost']);
$time=date("Y-m");
$begintime = $time."-05";
$endtime   = $time."-09";
echo "2015年11月5日到11月9日数据";
$sql_member="select id,dname,account from pft_member where account in(".implode(",",$account).")";
$stmt=Db::Connect()->prepare($sql_member);
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
    $result[$row['id']]=$row;
    $id_list.=$row['id'].',';
}
$id_list=rtrim($id_list,',');
Db::Conf($dbConf['remote_1']);
$sql="select sum(tnum) as s,aid from pft_order_statistics where ddate between  '$begintime' and '$endtime' and aid in($id_list) group by aid";
$stmt=Db::Connect()->prepare($sql);
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
    $res_aid[$row['aid']]=$row;

}
$sql_mid="select sum(tnum) as s,mid from pft_order_statistics where ddate between  '$begintime' and '$endtime' and mid in($id_list) and mid<>aid group by mid";
$stmt=Db::Connect()->prepare($sql_mid);
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
    $res_mid[$row['mid']]=$row;

}

foreach($res_mid as $mid_key=>$mid_val){
    $res[$mid_key]['sum']   =$mid_val['s']+$res_aid[$mid_key]['s'];
    $res[$mid_key]['dname'] =$result[$mid_key]['dname'];
}
$str = "业务量\taccount" ;
$file =  't.txt';
file_put_contents($file, $str."\n", FILE_APPEND | LOCK_EX);
foreach($res as $res_key=>$res_val){
    $str=$res_val['sum']."\t".$res_val['dname'] ;
    file_put_contents($file, $str."\n", FILE_APPEND | LOCK_EX);
}
echo "success";